﻿using System;

namespace DomainModel
{
    public class User : BaseEntity
    {
        protected User()
        {
            Approved = false;
        }

        public User(string login, string email, Role role)
            : this()
        {
            Login = login;
            Email = email;
            Role = role;
        }

        public virtual string Login { get; set; }
        public virtual string PasswordHash { get; set; }
        public virtual string Email { get; set; }
        public virtual bool Approved { get; set; }
        public virtual Role Role { get; set; }
        public virtual UserProfile UserProfile { get; set; }
        public virtual Group Group { get; set; }
        public virtual User Child { get; set; } // для родителя

        public virtual void SetPasswordHash(string password)
        {
            if (string.IsNullOrEmpty(password))
                PasswordHash = "";
            else
                PasswordHash = HashPassword(password);
        }

        public static string HashPassword(string password)
        {
            return password.GetHashCode().ToString();
        }
    }
}
